<template>
  <div>
    <el-card class="box-card">
      <el-form :inline="true" class="demo-form-inline">
        <el-form-item label="">
          <el-input placeholder="请输入关键字"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary">查询</el-button>
        </el-form-item>
      </el-form>
      <div>
        <el-button type="primary" icon="el-icon-plus">新增</el-button>
        <el-button type="primary" icon="el-icon-refresh" @click="handleRefresh">刷新</el-button>
      </div>
    </el-card>
    <el-card>
      <el-table :data="tbData" style="width: 100%">
        <el-table-column label="序号" width="60">
          <template slot-scope="scope">
            {{ scope.$index + 1 }}
          </template>
        </el-table-column>
        <el-table-column label="品类名称" property="cateName">
        </el-table-column>
        <el-table-column label="是否启用" property="isActived">
          <template slot-scope="scope">
            {{ scope.row.isActived ? "启用" : "禁用" }}
          </template>
        </el-table-column>
        <el-table-column label="更新时间" property="updatedTime">
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button
              type="primary"
              icon="el-icon-edit"
              size="mini"
              circle
              @click="handleEdit(scope.$index, scope.row)"
            ></el-button>
            <el-button
              type="danger"
              icon="el-icon-delete"
              size="mini"
              circle
              @click="handleDelete(scope.$index, scope.row)"
            ></el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>
<script>
const axios = require("axios");
export default {
  data() {
    return {
      tableData: [
        {
          date: "2016-05-02",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1518 弄",
        },
        {
          date: "2016-05-04",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1517 弄",
        },
        {
          date: "2016-05-01",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1519 弄",
        },
        {
          date: "2016-05-03",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1516 弄",
        },
      ],
      tbData: [],
    };
  },
  methods: {
    handleEdit(index, row) {
      console.log(index, row);
    },
    handleDelete(index, row) {
      console.log(index, row);
    },
    getData() {
      axios.get("/article/category").then(({ data }) => {
        console.log(data);
        this.tbData = data.list;
      }).catch(err=>{
        console.log(err);
      });
    },
    handleRefresh(){
      this.getData();
    }
  },
  created: function () {
    this.getData();
  },
};
</script>
<style>
.el-card__body {
  display: flex !important;
  justify-content: space-between;
}
</style>